import Vue from 'vue'
import Router from 'vue-router'
import {store} from '../store/index'
Vue.use(Router)

const router= new Router({
  routes: [
    {
      path: '/',
      redirect:'/menus'
    },
    {
      path:'/login',
      name:'login',
      component:()=>import('@/views/login/login')
    },
    {
      path:'/menus',
      name:'menus',
      redirect:'/menus/index',
      component:()=>import('@/views/menus/menus'),
      children:[
        {
          path:'/menus/index',
          name:'index',
          component:()=>import('@/views/menus/index'),
        },
        {
          path:'/menus/single-project',
          name:'singleProject',
          component:()=>import('@/views/detail/single/SingleProject'),
          meta:{
            type:'single',
            title:'单项目业绩查询',
          }
        },
        {
          path:'/menus/single-pushPerson',
          name:'singlePushPerson',
          component:()=>import('@/views/detail/single/SinglePushPerson'),
          meta:{
            type:'single',
            title:'单项目业绩查询'
          }
        },
        {
          path:'/menus/single-queryPerson',
          name:'singleQueryPerson',
          component:()=>import('@/views/detail/single/SingleQueryPerson'),
          meta:{
            type:'single',
            title:'单项目业绩查询'
          }
        },
        {
          path:'/menus/single-person',
          name:'singlePerson',
          component:()=>import('@/views/detail/single/SinglePerson'),
          meta:{
            type:'single',
            title:'单项目业绩查询'
          }
        },
        {
          path:'/menus/group-project',
          name:'groupProject',
          component:()=>import('@/views/detail/group/GroupProject'),
          meta:{
            type:'group',
            title:'团队业绩查询'
          }
        },
        {
          path:'/menus/group-chaDetail',
          name:'GroupChaDetail',
          component:()=>import('@/views/detail/group/GroupChaDetail'),
          meta:{
            type:'group',
            title:'团队业绩查询'
          }
        },
        {
          path:'/menus/group-person',
          name:'GroupPerson',
          component:()=>import('@/views/detail/group/GroupPerson'),
          meta:{
            type:'group',
            title:'团队业绩查询'
          }
        },
        {
          path:'/menus/group-pushPerson',
          name:'GroupPushPerson',
          component:()=>import('@/views/detail/group/GroupPushPerson'),
          meta:{
            type:'group',
            title:'团队业绩查询'
          }
        },
        {
          path:'/menus/group-queryPerson',
          name:'GroupQueryPerson',
          component:()=>import('@/views/detail/group/GroupQueryPerson'),
          meta:{
            type:'group',
            title:'团队业绩查询'
          }
        }
      ]
    }
  ]
})



router.beforeEach((to,from,next)=>{
  let token =localStorage.getItem("token")
  console.log(store.state)
  console.log(token)
  if(token && to.path==='/login'){
    next('/')
  }else if(!token && to.path!=='/login'){
    next('/login')
  }else if(!token && to.path==='/login'){
    next()
  }else{
    next()
  }
})
export default router
